﻿#include "stdafx.h"
#include "C_CurrentMonitor.h"

#include "MathUtils.h"

/*
-----==========================================================-----
		类：		电流监视器 数据类.h
		作者：		drill_up
		所属模块：	监视器模块
		功能：		电流监视器的数据类对象。
-----==========================================================-----
*/

C_CurrentMonitor::C_CurrentMonitor() : C_UndoDataBase(){

	// > 属性
	this->name = "";				//名称
	
	// > 坐标
	this->x1 = 0;
	this->y1 = 0;
	this->z1 = 0;
	this->x2 = 0;
	this->y2 = 0;
	this->z2 = 0;
	this->x3 = 0;
	this->y3 = 0;
	this->z3 = 0;
	this->directionInverted = false;

}

C_CurrentMonitor::~C_CurrentMonitor(){
}



/*-------------------------------------------------
		描述 - 获取属性描述
*/
QPair<QString, QString> C_CurrentMonitor::getAttributesDesc() {
	QPair<QString, QString> context_pair;

	context_pair.first.append(QObject::tr("Type"));
	context_pair.first.append("\n");
	context_pair.second.append("= ");
	context_pair.second.append(QObject::tr("CurrentMonitor"));
	context_pair.second.append("\n");

	context_pair.first.append("P1");
	context_pair.first.append("\n");
	context_pair.second.append("= (");
	context_pair.second.append(QString::number(this->x1));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->y1));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->z1));
	context_pair.second.append(")");
	context_pair.second.append("\n");

	context_pair.first.append("P2");
	context_pair.first.append("\n");
	context_pair.second.append("= (");
	context_pair.second.append(QString::number(this->x2));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->y2));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->z2));
	context_pair.second.append(")");
	context_pair.second.append("\n");

	context_pair.first.append("P3");
	context_pair.first.append("\n");
	context_pair.second.append("= (");
	context_pair.second.append(QString::number(this->x3));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->y3));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->z3));
	context_pair.second.append(")");
	context_pair.second.append("\n");

	if (this->isCollinear() != true) {
		DSEM::Point3D p4 = this->getQuadrilateralVertex();

		context_pair.first.append("P4");
		context_pair.first.append("\n");
		context_pair.second.append("= (");
		context_pair.second.append(QString::number(p4.X()));
		context_pair.second.append(",");
		context_pair.second.append(QString::number(p4.Y()));
		context_pair.second.append(",");
		context_pair.second.append(QString::number(p4.Z()));
		context_pair.second.append(")");
		context_pair.second.append("\n");
	}

	return context_pair;
}

/*-------------------------------------------------
		电流环路 - 三点是否共线
*/
bool C_CurrentMonitor::isCollinear() {
	return this->util_isCollinear(DSEM::Point3D(this->x1, this->y1, this->z1), DSEM::Point3D(this->x2, this->y2, this->z2), DSEM::Point3D(this->x3, this->y3, this->z3));
}
/*-------------------------------------------------
		电流环路 - 根据三点算出第四个点
*/
DSEM::Point3D C_CurrentMonitor::getQuadrilateralVertex() {
	return this->util_getQuadrilateralVertex(DSEM::Point3D(this->x1, this->y1, this->z1), DSEM::Point3D(this->x2, this->y2, this->z2), DSEM::Point3D(this->x3, this->y3, this->z3));
}
/*-------------------------------------------------
		电流环路 - 三点是否共线
*/
bool C_CurrentMonitor::util_isCollinear(const DSEM::Point3D& p1, const DSEM::Point3D& p2, const DSEM::Point3D& p3) {
	return DSEM::MathUtils::IsPointsCollinear(p1, p2, p3, DSEM::Precision::Confusion());
}
/*-------------------------------------------------
		电流环路 - 根据三点算出第四个点
*/
DSEM::Point3D C_CurrentMonitor::util_getQuadrilateralVertex(const DSEM::Point3D& p1, const DSEM::Point3D& p2, const DSEM::Point3D& p3) {
	return DSEM::MathUtils::GetLastQuadrilateralVertex(p1, p2, p3);
}


/*-------------------------------------------------
		访问器 - 获取子类类名
*/
QString C_CurrentMonitor::get__CLASS_NAME__(){
	return "C_CurrentMonitor";
}
/*-------------------------------------------------
		访问器 - 获取子类类名（中文名）
*/
QString C_CurrentMonitor::get__CLASS_NAME__Chinese(){
	return "电流监视器";
}
/*-------------------------------------------------
		访问器 - 获取所有继承的类名
*/
QStringList C_CurrentMonitor::get__CLASS_INHERITED_LIST__(){
	return C_UndoDataBase::get__CLASS_INHERITED_LIST__() << "C_CurrentMonitor";
}
/*-------------------------------------------------
		访问器 - 是否继承了某类
*/
bool C_CurrentMonitor::get__CLASS_IS_INSTANCE_OF__(QString class_name){
	return this->get__CLASS_INHERITED_LIST__().contains(class_name);
}
/*-------------------------------------------------
		访问器 - 原型复制对象
*/
C_CurrentMonitor C_CurrentMonitor::clone(){
	return C_CurrentMonitor(*this);
}
QSharedPointer<C_CurrentMonitor> C_CurrentMonitor::clonePtr(){
	return QSharedPointer<C_CurrentMonitor>(new C_CurrentMonitor(*this));
}
C_UndoDataBasePtr C_CurrentMonitor::cloneParentPtr(){
	return this->clonePtr();
}

/*-------------------------------------------------
		复制对象
*/
void C_CurrentMonitor::copyFrom(C_CurrentMonitor* a){

	// > 属性
	this->name = a->name;

	// > 坐标
	this->x1 = a->x1;
	this->y1 = a->y1;
	this->z1 = a->z1;
	this->x2 = a->x2;
	this->y2 = a->y2;
	this->z2 = a->z2;
	this->x3 = a->x3;
	this->y3 = a->y3;
	this->z3 = a->z3;
	this->directionInverted = a->directionInverted;
}
/*-------------------------------------------------
		运算符重载
*/
const bool C_CurrentMonitor::operator== (const C_CurrentMonitor& a)const {
	return C_UndoDataBase::operator==(a);
}
/*-------------------------------------------------
		空判断
*/
bool C_CurrentMonitor::isNull(){
	return C_UndoDataBase::isNull();
}

/*-------------------------------------------------
		实体类 -> QJsonObject
*/
QJsonObject C_CurrentMonitor::getJsonObject_undoChildData(){
	QJsonObject obj;

	// > 属性
	obj.insert("name", this->name);

	// > 坐标
	obj.insert("x1", this->x1);
	obj.insert("y1", this->y1);
	obj.insert("z1", this->z1);
	obj.insert("x2", this->x2);
	obj.insert("y2", this->y2);
	obj.insert("z2", this->z2);
	obj.insert("x3", this->x3);
	obj.insert("y3", this->y3);
	obj.insert("z3", this->z3);
	obj.insert("directionInverted", this->directionInverted);

	return obj;
}
/*-------------------------------------------------
		QJsonObject -> 实体类
*/
void C_CurrentMonitor::setJsonObject_undoChildData(QJsonObject obj){

	// > 属性
	this->name = obj.value("name").toString();

	// > 参数
	this->x1 = obj.value("x1").toDouble();
	this->y1 = obj.value("y1").toDouble();
	this->z1 = obj.value("z1").toDouble();
	this->x2 = obj.value("x2").toDouble();
	this->y2 = obj.value("y2").toDouble();
	this->z2 = obj.value("z2").toDouble();
	this->x3 = obj.value("x3").toDouble();
	this->y3 = obj.value("y3").toDouble();
	this->z3 = obj.value("z3").toDouble();
	this->directionInverted = obj.value("directionInverted").toBool();

}
